﻿/*
* CjsjParser.cs
*
* 功 能： 采集数据转换算法
* 类 名： CjsjParser
*
* Ver    变更日期  20130723   负责人  黄永生  变更内容
* ───────────────────────────────────

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DQYT.HTDZ.Common
{
    /// <summary>
    /// 把采集的原始数据转换成入库数据   
    /// </summary>
   public  class CjsjParser
    { 
        public CjsjParser()
        { }
       /// <summary>
       /// 转换井号
       /// </summary>
       /// <param name="WELLID"></param>
       /// <returns></returns>
        public string getWELLIDParser(string WELLID)
        {
            if (WELLID!="")
                return WELLID;
            return "井号" + DateTime.Now.ToShortTimeString();
        }
       /// <summary>
       /// 转换检测日期
       /// </summary>
       /// <param name="JCRQ"></param>
       /// <returns></returns>
        public DateTime getJCRQParser(DateTime? JCRQ)
        {
            if (JCRQ.HasValue)
                return JCRQ.Value;
            return DateTime.Now;
        }
       /// <summary>
       /// 转换开始时间
       /// </summary>
       /// <param name="KSSJ"></param>
       /// <returns></returns>
        public DateTime getKSSJParser(DateTime? KSSJ)
        {
            if (KSSJ.HasValue)
                return KSSJ.Value;
            return DateTime.Now;
        }
       /// <summary>
       /// 转换结束时间
       /// </summary>
       /// <param name="JSSJ"></param>
       /// <returns></returns>
        public DateTime getJSSJParser(DateTime? JSSJ)
        {
            if (JSSJ.HasValue)
                return JSSJ.Value;
            return DateTime.Now;

        }
       /// <summary>
       /// 转换采集总时间
       /// </summary>
       /// <param name="CJZSJ"></param>
       /// <returns></returns>
        public string getCJZSJParser(string CJZSJ)
        {
            if (CJZSJ!=null)
            {
                if (CJZSJ.Split(':').Length == 1)
                   return "00:00:" + CJZSJ;
                else if (CJZSJ.Split(':').Length == 2)
                    return "00:" + CJZSJ;
                return CJZSJ;
            }
            return (DateTime.Now - DateTime.Now).ToString();
        }
       /// <summary>
       /// 转换采集频率
       /// </summary>
       /// <param name="CJPL"></param>
       /// <returns></returns>
        public decimal getCJPLParser(decimal? CJPL)
        {
            if (CJPL.HasValue)
                return CJPL.Value;
            return -1;
        }
       /// <summary>
       /// 转换采集总点数
       /// </summary>
       /// <param name="CJZDS"></param>
       /// <returns></returns>
        public decimal getCJZDSParser(decimal? CJZDS)
        {
            if (CJZDS.HasValue)
                return CJZDS.Value;
            return -1;
        }
       /// <summary>
       /// 转换上冲程点数
       /// </summary>
       /// <param name="SCCDS"></param>
       /// <returns></returns>
        public decimal getSCCDSParser(decimal? SCCDS)
        {
            if (SCCDS.HasValue)
                return SCCDS.Value;
            return -1;

        }
       /// <summary>
       /// 转换下冲程点数
       /// </summary>
       /// <param name="XCCDS"></param>
       /// <returns></returns>
        public decimal getXCCDSParser(decimal? XCCDS)
        {
            if (XCCDS.HasValue)
                return XCCDS.Value;
            return -1;
        }
       /// <summary>
       /// 转换抽油机ID
       /// </summary>
       /// <param name="PULLID"></param>
       /// <returns></returns>
        public decimal getPULLIDParser(decimal? PULLID)
        {
            if (PULLID.HasValue)
                return PULLID.Value;
            return -1;
        }
        /// <summary>
        /// 电机ID
        /// </summary>
        /// <param name="PULLID"></param>
        /// <returns></returns>
        public decimal getDJIDParser(decimal? DJID)
        {
            if (DJID.HasValue)
                return DJID.Value;
            return -1;
        }
        /// <summary>
        /// 配电柜ID
        /// </summary>
        /// <param name="PULLID"></param>
        /// <returns></returns>
        public decimal getPDGIDParser(decimal? PDGID)
        {
            if (PDGID.HasValue)
                return PDGID.Value;
            return -1;
        }
       /// <summary>
        /// 转换管理单位
       /// </summary>
       /// <param name="GLDW"></param>
       /// <returns></returns>
        public string  getGLDWParser(string GLDW)
        {
            if (GLDW != null)
                return GLDW;
            return "无值";
        }
        // <summary>
        /// 转换检测单位
        /// </summary>
        /// <param name="GLDW"></param>
        /// <returns></returns>
        public string getJCDWParser(string JCDW)
        {
            if (JCDW != null)
                return JCDW;
            return "无值";
        }
        // <summary>
        /// 转换测试人
        /// </summary>
        /// <param name="GLDW"></param>
        /// <returns></returns>
        public string getCSRParser(string CSR)
        {
            if (CSR != null)
                return CSR;
            return "无值";
        }
        // <summary>
        /// 转换采集设备型号
        /// </summary>
        /// <param name="GLDW"></param>
        /// <returns></returns>
        public string getCJSBXHParser(string CJSBXH)
        {
            if (CJSBXH != null)
                return CJSBXH;
            return "无值";
        }
        // <summary>
        /// 转换采集设备版本
        /// </summary>
        /// <param name="GLDW"></param>
        /// <returns></returns>
        public string getCJSBBBParser(string CJSBBB)
        {
            if (CJSBBB != null)
                return CJSBBB;
            return "无值";
        }
        // <summary>
        /// 转换上传软件版本
        /// </summary>
        /// <param name="GLDW"></param>
        /// <returns></returns>
        public string getSCRJBBParser(string SCRJBB)
        {
            if (SCRJBB != null)
                return SCRJBB;
            return "无值";
        }
        /// <summary>
        /// 转换电流
        /// </summary>
        /// <param name="DD"></param>
        /// <returns></returns>
        public float getDLParser(float? DL)
        {
            if(DL.HasValue)
              return DL.Value / 10;
            return -1;

        }
        /// <summary>
        /// 转换电压
        /// </summary>
        /// <param name="DY"></param>
        /// <returns></returns>
        public float getDYParser(float? DY)
        {
            if(DY.HasValue)
              return DY.Value / 10;
            return -1;
        }
        /// <summary>
        /// 转换有功功率
        /// </summary>
        /// <param name="HYGGL"></param>
        /// <returns></returns>
        public float getYGGLParser(float? YGGL)
        {
            if(YGGL.HasValue)
            return ((YGGL .Value< 32768) ? YGGL.Value : -1 * (65536 - YGGL.Value)) / 100;
            return -1;
        }
        /// <summary>
        /// 转换无功功率
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public float getWGGLParser(float? WGGL)
        {
            if(WGGL.HasValue)
              return ((WGGL.Value < 32768) ? WGGL.Value : -1 * (65536 - WGGL.Value)) / 100;
            return -1;
        }
        /// <summary>
        /// 转换功率因数
        /// </summary>
        /// <param name="GLYS"></param>
        /// <returns></returns>
        public float getGLYSParser(float? GLYS)
        {
            if(GLYS.HasValue)
              return (GLYS.Value < 32768) ? GLYS.Value / 100 : -(65536 - GLYS.Value) / 100;
            return -1;
        }
        /// <summary>
        /// 转换采集频率
        /// </summary>
        /// <param name="CJPL"></param>
        /// <returns></returns>
        public float getPLParser(float? PL)
        {
            if(PL.HasValue)
              return PL.Value / 10;
            return -1;
        }
        /// <summary>
        /// 转换有功能耗
        /// </summary>
        /// <param name="YGNHT"></param>
        /// <param name="YGNHW"></param>
        /// <returns></returns>
        public float getYGNHParser(float? YGNHT, float? YGNHW)
        {
            if(YGNHT.HasValue&&YGNHW.HasValue)
              return (YGNHT.Value < 32768) ? (YGNHT.Value * 65536 + YGNHW.Value) : -((65536 - YGNHT.Value) * 65536 + YGNHW.Value);
            return -1;
        }
        /// <summary>
        /// 转换无功能耗
        /// </summary>
        /// <param name="WGNHT"></param>
        /// <param name="WGNHW"></param>
        /// <returns></returns>
        public float getWGNHParser(float? WGNHT, float? WGNHW)
        {
            if(WGNHT.HasValue&&WGNHW.HasValue)
              return (WGNHT.Value < 32768) ? (WGNHT.Value * 65536 + WGNHW.Value) : -((65536 - WGNHT.Value) * 65536 + WGNHW.Value);
            return -1;
        }
        /// <summary>
        /// 转换温度
        /// </summary>
        /// <param name="WD"></param>
        /// <returns></returns>
        public float  getWDPaser(float? WD)
        {
            if(WD.HasValue)
              return WD.Value ;
            return -1;
        }
       /// <summary>
       /// 转换电机输出扭矩
       /// </summary>
       /// <param name="DJSCNJ"></param>
       /// <returns></returns>
        public float getDJSCNJParser(float? DJSCNJ)
        {
            if(DJSCNJ.HasValue)
              return DJSCNJ.Value;
            return -1;
        }
        /// <summary>
        /// 转换电机额定转速
        /// </summary>
        /// <param name="DJEDZS"></param>
        /// <returns></returns>
        public float getDJEDZSParser(float? DJEDZS)
        {
            if(DJEDZS.HasValue)
              return DJEDZS.Value;
            return -1;
        }
       /// <summary>
       /// 转换减速机输出扭矩
       /// </summary>
       /// <param name="JSJSCNJ"></param>
       /// <returns></returns>
        public float getJSJSCNJParser(float? JSJSCNJ)
        {
            if(JSJSCNJ.HasValue)
              return JSJSCNJ.Value ;
            return -1;
        }
       /// <summary>
       /// 转换电机效率
       /// </summary>
       /// <param name="DJXL"></param>
       /// <returns></returns>
        public float getDJXLParser(float? DJXL)
        {
            if(DJXL .HasValue)
            return DJXL.Value;
            return -1;
        }
        /// <summary>
        /// 转换曲柄转角
        /// </summary>
        /// <param name="QBZJ"></param>
        /// <returns></returns>
        public float getQBZJParser(float? QBZJ)
        {
            if(QBZJ.HasValue)
              return QBZJ.Value;
            return -1;
        }
       /// <summary>
       /// 转换驴头位移
       /// </summary>
       /// <param name="LTWY"></param>
       /// <returns></returns>
        public float getLTWYParser(float? LTWY)
        {
            if(LTWY.HasValue)
              return LTWY.Value ;
            return -1;
        }
        /// <summary>
        /// 转换悬点载荷
        /// </summary>
        /// <param name="XDZH"></param>
        /// <returns></returns>
        public float getXDZHParser(float? XDZH)
        {
            if(XDZH.HasValue)
              return XDZH.Value;
            return -1;
        }
        /// <summary>
        /// 转换油压
        /// </summary>
        /// <param name="YY"></param>
        /// <returns></returns>
        public float getYYParser(float? YY)
        {
            if(YY.HasValue)
            return YY.Value ;
            return -1;
        }
        /// <summary>
        /// 转换套压
        /// </summary>
        /// <param name="TY"></param>
        /// <returns></returns>
        public float getTYParser(float? TY)
        {
            if (TY.HasValue)
              return TY.Value ;
            return -1;
        }
        /// <summary>
        /// 转换液面高度
        /// </summary>
        /// <param name="YMGD"></param>
        /// <returns></returns>
        public float getYMGDParser(float? YMGD)
        {
            if (YMGD.HasValue )
              return YMGD.Value ;
            return -1;
        }
        /// <summary>
        /// 转换A相视在功率
        /// </summary>
        /// <param name="SZGL"></param>
        /// <returns></returns>
        public float getASZGLParser(float? ADY, float? ADL)
        {
            if (ADY.HasValue && ADL.HasValue)
                return ADY.Value * ADL.Value ;
            return -1;
        }
        /// <summary>
        /// 转换B相视在功率
        /// </summary>
        /// <param name="SZGL"></param>
        /// <returns></returns>
        public float getBSZGLParser(float? BDY, float? BDL)
        {
            if (BDY.HasValue && BDL.HasValue)
                return BDY.Value * BDL.Value;
            return -1;
        }
        /// <summary>
        /// 转换C相视在功率
        /// </summary>
        /// <param name="SZGL"></param>
        /// <returns></returns>
        public float getCSZGLParser(float? CDY, float? CDL)
        {
            if (CDY.HasValue && CDL.HasValue)
                return CDY.Value * CDL.Value;
            return -1;
        }
        /// <summary>
        /// 转换A相视在功率
        /// </summary>
        /// <param name="SZGL"></param>
        /// <returns></returns>
        public float getHSZGLParser(float? ADY,float? BDY,float? CDY)
        {
            if(ADY.HasValue &&BDY.HasValue&&CDY.HasValue)
               return (ADY.Value  * ADY .Value + BDY .Value * BDY.Value  + CDY.Value  * CDY.Value ) / 1000;
            return -1;
        }
     

    }
}
